package com.xnyzc.lhy.order.controller.driver;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.param.cms.user.CmsOaCUserImportParam;
import com.xnyzc.lhy.order.entity.result.cms.driver.CmsOaDUserImport;
import com.xnyzc.lhy.order.service.cms.driver.ICmsOaDUserImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 导入
 * @Author zhuyubin
 * @Date 2019-08-28 19:41
 **/
@RestController
@RequestMapping(value = "cmsapi/cmsOaDUserImport")
public class CmsOaDUserImportController {

    @Autowired
    private ICmsOaDUserImportService iCmsOaDUserImportService;

    /**
     * 导入
     * @param cmsOaCUserImportParam 入参
     * @return
     */
    @PostMapping(value = "driveImport")
    public Rv driveImport(@RequestBody CmsOaCUserImportParam cmsOaCUserImportParam){
        long sysUserId = TokenUtil.getTokenUserId();
        String tag = TokenUtil.getTag();
        String clientId = TokenUtil.getClientId();
        if (CheckUtil.objIsEmpty(tag, clientId)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        List<CmsOaDUserImport> cmsOaDUserImportList = cmsOaCUserImportParam.getCmsOaDUserImportList();
        if (CheckUtil.objIsEmpty(cmsOaDUserImportList)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iCmsOaDUserImportService.userImport(sysUserId, tag, clientId, cmsOaDUserImportList));
    }
}
